/*****************************************************************************
 * plum_kal_thread.h
 *
 * Copyright (C) 2020 Jeasonvor <1101627719@qq.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

#ifndef __PLUM_KAL_THREAD_H__
#define __PLUM_KAL_THREAD_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

#define PLUM_KAL_THREAD_STACK_DEFAULT (1024 * 4)

#define PLUM_KAL_THREAD_NAME_MAX 16

/*****************************************************************************
 * Public Types
 ****************************************************************************/

typedef enum {
    PLUM_KAL_THREAD_PRIORITY_IDLE,
    PLUM_KAL_THREAD_PRIORITY_1,
    PLUM_KAL_THREAD_PRIORITY_2,
    PLUM_KAL_THREAD_PRIORITY_3,
    PLUM_KAL_THREAD_PRIORITY_4,
    PLUM_KAL_THREAD_PRIORITY_5,
    PLUM_KAL_THREAD_PRIORITY_6,
    PLUM_KAL_THREAD_PRIORITY_7,
    PLUM_KAL_THREAD_PRIORITY_8,
    PLUM_KAL_THREAD_PRIORITY_9,
    PLUM_KAL_THREAD_PRIORITY_10,
    PLUM_KAL_THREAD_PRIORITY_11,
    PLUM_KAL_THREAD_PRIORITY_12,
    PLUM_KAL_THREAD_PRIORITY_13,
    PLUM_KAL_THREAD_PRIORITY_14,
    PLUM_KAL_THREAD_PRIORITY_15,
    PLUM_KAL_THREAD_PRIORITY_17,
    PLUM_KAL_THREAD_PRIORITY_18,
    PLUM_KAL_THREAD_PRIORITY_19,
    PLUM_KAL_THREAD_PRIORITY_20,
    PLUM_KAL_THREAD_PRIORITY_21,
    PLUM_KAL_THREAD_PRIORITY_22,
    PLUM_KAL_THREAD_PRIORITY_23,
    PLUM_KAL_THREAD_PRIORITY_24,
    PLUM_KAL_THREAD_PRIORITY_25,
    PLUM_KAL_THREAD_PRIORITY_26,
    PLUM_KAL_THREAD_PRIORITY_27,
    PLUM_KAL_THREAD_PRIORITY_28,
    PLUM_KAL_THREAD_PRIORITY_29,
    PLUM_KAL_THREAD_PRIORITY_30,
    PLUM_KAL_THREAD_PRIORITY_31,
} plum_kal_thread_priority_t;

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief:  创建线程
 *
 * @param[in]:  name        -   线程名称
 * @param[in]:  task        -   线程实现
 * @param[in]:  arg         -   线程参数
 * @param[in]:  pri         -   线程优先级
 * @param[in]:  stack_sz    -   线程堆栈空间
 *
 * @return: 返回错误码
 *
 * @note:   线程退出需要系统支持自动回收技术
 * */
plum_s32 plum_kal_thread_create(PLUM_CONST plum_s8 *name,
                                plum_void (*task)(plum_void *arg),
                                plum_void *arg, plum_kal_thread_priority_t pri,
                                plum_u32 stack_sz);

/**
 * @brief:   删除线程
 *
 * @param[in]:  name  -   线程名称
 *
 * @return: 成功  -   返回0
 *          失败    -   返回错误码
 */
plum_s32 plum_kal_thread_delete(PLUM_CONST plum_s8 *name);

/**
 * @brief:   挂起线程
 *
 * @param[in]:  name  -   线程名称
 *
 * @return: 返回错误码
 */
plum_s32 plum_kal_thread_suspend(PLUM_CONST plum_s8 *name);

/**
 * @brief:   恢复线程
 *
 * @param[in]:  name  -   线程名称
 *
 * @return: 返回错误码
 */
plum_s32 plum_kal_thread_resume(PLUM_CONST plum_s8 *name);

/**
 * @brief:   展示线程信息
 *
 * @param[in]:  name    -   线程名称，如果为plum_null则为所有
 *
 * @return:
 */
plum_void plum_kal_thread_show(PLUM_CONST plum_s8 *name);

/**
 * @brief:  线程延时
 *
 * @param[in]:  ms  -   毫秒延时
 *
 * @return:
 */
plum_void plum_kal_thread_delay(plum_u32 ms);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __PLUM_KAL_THREAD_H__ */
/****************************************************************************/

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
